package com.example.apprank.controller;

import com.example.apprank.common.controller.BaseController;
import com.example.apprank.common.domain.PageQueryDTO;
import com.example.apprank.common.domain.Result;
import com.example.apprank.common.domain.TableDataInfo;
import com.example.apprank.module.AppAndroid;
import com.example.apprank.module.AppIos;
import com.example.apprank.service.impl.IAppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/appRank")
public class AppRankController extends BaseController {
    @Autowired
    private IAppService appService;

    @GetMapping("/revenue")
    public Result<Long> getRevenueSum() {
        return Result.success(appService.getRevenueSum());
    }
    @GetMapping("/category")
    public Result<Integer> getCategoryNum() {
        return Result.success(appService.getCategory());
    }
    @GetMapping("/getNum")
    public Result<Integer> getNum() {
        return Result.success(appService.getAppNum());
    }
    @GetMapping("/list")
    public TableDataInfo getApp(PageQueryDTO pageQueryDTO) {
        return appService.getApp(pageQueryDTO);
    }

    @GetMapping("/getApp/ios")
    public Result<AppIos> selectIosAppById(@RequestParam("appId") Long appId) {
        return Result.success(appService.selectIosAppById(appId));
    }

    @GetMapping("/getApp/android")
    public Result<AppAndroid> selectAndroidAppById(@RequestParam("appId") String appId) {
        return Result.success(appService.selectAndroidAppById(appId));
    }
    //1.如何将数据存储到es当中
    //2.es在查询的时候如何返回给前端内容呢，我觉得应该还是和对象类有关系的
    //3.在拿到前端的数据的时候，如何进行编写es的查询语句呢
    //如果这样的话，这都解决的话，搜索框的内容就解决了。

    @GetMapping("/es")
    public TableDataInfo getAppByES(@RequestParam("query") String query) {
        return getTableDataInfo(appService.getAppByES(query));
    }
    @GetMapping("/save")
    public void saveDataES() {
        appService.savaDataES();
    }
    @GetMapping("/test")
    public Result<List<String>> test(@RequestParam("appDetailUrl") String appDetailUrl) throws Exception {
        return Result.success( appService.getPngUrls(appDetailUrl));
    }
}

